//
//  MainGameViewController.m
//  Bluetooth Mini Games
//
//  Created by iD Student on 7/15/13.
//  Copyright (c) 2013 ZTBWorks. All rights reserved.
//

#import "MainGameViewController.h"
@interface MainGameViewController ()

@end

@implementation MainGameViewController

- (id) initWithGamesPerMode:(NSInteger)gameNumber withGames:(NSArray *)games
{
    numberOfGamesPerMode = gameNumber;
    gamesArray = games;
    return self;
}

- (void)viewDidLoad
{
    [player1ScoreLabel setTransform:CGAffineTransformMakeRotation(DEGREES_TO_RADIANS(180))];
    [super viewDidLoad];
    ChangeToWhiteView *gameView = [[ChangeToWhiteView alloc]init];
    [self.view addSubview:gameView];
    [gameView startGame];
    gameNumber = 0;
}

#pragma mark game

- (void) gameLoopWithButton:(UIButton *)button
{
    if (gameNumber > numberOfGamesPerMode) {
        gameMode = arc4random() % gamesArray.count - 1;
    } else {
        gameNumber ++;
    }
    
}

- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)session:(GKSession *)session peer:(NSString *)peerID didChangeState:(GKPeerConnectionState)state
{
    switch (state) {
        case GKPeerStateDisconnected:
            [self dismissViewControllerAnimated:YES completion:^{
                UIAlertView *alertView = [[UIAlertView alloc]initWithTitle:@"Partner Disconnected" message:@"Please click 'Connect to Partner' to reconnect." delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
                [alertView show];
            }];
            break;
    }
}

- (void) updateScoreOfPlayer:(NSInteger)player correct:(BOOL)answer
{
    if(answer == true)
    {
        if (player == 1) {
            player1score += 1;
        } else {
            player2score += 1;
        }
    } else {
        if (player == 1) {
            player1score -= 1;
        } else {
            player2score -= 1;
        }
    }
    player1ScoreLabel.text = [NSString stringWithFormat:@"Player 1 Score:%d  |  Player 2 Score: %d", player1score, player2score];
    player2ScoreLabel.text = [NSString stringWithFormat:@"Player 1 Score:%d  |  Player 2 Score: %d", player1score, player2score];
}

@end
